package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.MemberBindRecordDto;
import edu.suda.xsap.dto.convert.MemberBindRecordConvert;
import edu.suda.xsap.entity.MemberBindRecord;
import edu.suda.xsap.mapper.MemberBindRecordMapper;
import edu.suda.xsap.service.MemberBindRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberBindRecordServiceImpl implements MemberBindRecordService {
    @Autowired
    private MemberBindRecordMapper memberCardBindMapper;
    @Autowired
    private MemberBindRecordConvert memberBindRecordConvert;

    @Override
    public void bind(MemberBindRecordDto memberBindRecordDto) {
        MemberBindRecord memberBindRecord = memberBindRecordConvert.toEntity(memberBindRecordDto);
        memberCardBindMapper.save(memberBindRecord);
    }

    @Override
    public void update(MemberBindRecordDto memberBindRecordDto) {
        MemberBindRecord memberBindRecord = memberBindRecordConvert.toEntity(memberBindRecordDto);
        memberCardBindMapper.update(memberBindRecord);
    }

    @Override
    public MemberBindRecordDto findById(Integer id) {
        MemberBindRecord memberBindRecord = memberCardBindMapper.findById(id);
        return memberBindRecordConvert.toDto(memberBindRecord);
    }

    @Override
    public List<MemberBindRecordDto> findByMemberId(Integer memberId) {
        List<MemberBindRecord> records = memberCardBindMapper.findByMemberId(memberId);
        return memberBindRecordConvert.toDtoList(records);
    }

    @Override
    public List<MemberBindRecordDto> findByCardId(Integer cardId) {
        List<MemberBindRecord> records = memberCardBindMapper.findByCardId(cardId);
        return memberBindRecordConvert.toDtoList(records);
    }

    @Override
    public List<MemberBindRecordDto> findAll() {
        List<MemberBindRecord> records = memberCardBindMapper.findAll();
        return memberBindRecordConvert.toDtoList(records);
    }

    @Override
    public void delete(Integer id) {
        memberCardBindMapper.delete(id);
    }

    //List<Integer> findCardIdsByMemberId(Integer memberId);
    @Override
    public List<Integer> findCardIdsByMemberId(Integer memberId) {
        return memberCardBindMapper.findCardIdsByMemberId(memberId);
    }
    }
